<template>
  <el-config-provider :locale="locale" :size="assemblySize" :button="buttonConfig">
    <router-view></router-view>
    <!-- <div v-else class="not_pc_message_box">
      <i class="iconfont icon-zhuyi"></i>
      <span class="not_pc_message_text">此网站只支持电脑端访问!</span>
    </div> -->
  </el-config-provider>
</template>

<script setup lang="ts">
import { onMounted, reactive, computed } from "vue";
import { useI18n } from "vue-i18n";
import { getBrowserLang } from "@/utils";
import { useTheme } from "@/hooks/useTheme";
import { ElConfigProvider } from "element-plus";
import { LanguageType } from "./stores/interface";
import { useGlobalStore } from "@/stores/modules/global";
import en from "element-plus/es/locale/lang/en";
import zhCn from "element-plus/es/locale/lang/zh-cn";
// import { isPC } from "@/utils/sys";

const globalStore = useGlobalStore();

// init theme
const { initTheme } = useTheme();
initTheme();

// init language
const i18n = useI18n();
onMounted(() => {
  const language = globalStore.language ?? getBrowserLang();
  i18n.locale.value = language;
  globalStore.setGlobalState("language", language as LanguageType);
});

// element language
const locale = computed(() => {
  if (globalStore.language == "zh") return zhCn;
  if (globalStore.language == "en") return en;
  return getBrowserLang() == "zh" ? zhCn : en;
});

// element assemblySize
const assemblySize = computed(() => globalStore.assemblySize);

// element button config
const buttonConfig = reactive({ autoInsertSpace: false });

onMounted(() => {
  window.onload = function () {
    document.addEventListener("gesturestart", function (e) {
      e.preventDefault();
    });

    document.addEventListener("dblclick", function (e) {
      e.preventDefault();
    });

    document.addEventListener("touchstart", function (event) {
      if (event.touches.length > 1) {
        event.preventDefault();
      }
    });

    let lastTouchEnd = 0;

    document.addEventListener(
      "touchend",
      function (event) {
        let now = new Date().getTime();

        if (now - lastTouchEnd <= 300) {
          event.preventDefault();
        }

        lastTouchEnd = now;
      },
      false
    );
  };

  // 屏蔽原始右键菜单
  document.oncontextmenu = function (event) {
    event = event || window.event;
    // 阻止默认的右键菜单
    if (event.preventDefault) {
      event.preventDefault();
    } else {
      event.returnValue = false; // IE浏览器的兼容性写法
    }
  };
});
</script>

<style lang="scss" scoped>
.not_pc_message_box {
  position: absolute;
  top: 30%;
  width: 100vw;
  font-size: 20px;
  text-align: center;
  letter-spacing: 2px;
  transform: translateY(-50%);
  .iconfont {
    position: relative;
    top: 6px;
    font-size: 36px;
    color: blue;
  }
}

* {
  font-family: "VIVO1" !important;
}
</style>
